package br.ufpe.cin.vspeed.util;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;

/**
 * @author <a href="mailto:andreza.lba@gmail.com">Andreza Leite de Alencar</a>
 */
public final class ClipboardUtils {

	private ClipboardUtils() {
	}

	public static String paste() {
		String result = "";
		final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		final Transferable contents = clipboard.getContents(null);
		final boolean hasText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
		if (hasText) {
			try {
				result = (String) contents.getTransferData(DataFlavor.stringFlavor);
			} catch (final Exception ex) {
				ex.printStackTrace();
			}
		}
		return result;
	}

}
